<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>测评问卷</title>
    <meta name="context-path" th:content="@{/}"/>
    <link rel="stylesheet" th:href="@{/resources/matrix/css/bootstrap.min.css}"/>
    <link rel="stylesheet" th:href="@{/resources/matrix/css/bootstrap-responsive.min.css}"/>
    <link rel="stylesheet" th:href="@{/resources/matrix/css/matrix-style.css}"/>
    <link rel="stylesheet" th:href="@{/resources/matrix/css/matrix-media.css}"/>
    <link rel="stylesheet" th:href="@{/resources/matrix/css/matrix-full.css}"/>
    <link rel="stylesheet" th:href="@{/resources/matrix/font-awesome/css/font-awesome.css}"/>
    <link rel="stylesheet" th:href="@{/resources/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/resources/jquery-easyui/themes/material/easyui.css}"/>
    <link rel="stylesheet" th:href="@{/resources/css/website.css}"/>
</head>
<body class="childbody">
<div class="container-fluid">
    <!--Chart-box-->
    <div class="row-fluid">
        <div class="widget-box">
            <div class="widget-title bg_lg"><span class="icon"><i class="icon-search"></i></span>
                <h5>查询</h5>
            </div>
            <div class="widget-content nopadding">
                <form id="queryform" action="#" method="get" class="form-horizontal query-form">
                    <div class="row-fluid query-row">
                        <div class="span3">
                            <div class="control-group">
                                <label class="control-label query-control-label">名称</label>
                                <div class="controls query-controls">
                                    <input type="text" name="name" class="span11" placeholder="请输入名称">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        <button id="btnSearch" type="button" class="btn btn-primary">查询</button>
                    </div>
                </form>
            </div>
        </div>
        <!--End-Chart-box-->
        <div class="row-fluid">
            <div class="span6">
                <div class="widget-box">
                    <div class="widget-title"><span class="icon"> <i class="icon-th"></i> </span>
                        <h5>测评问卷</h5>
                    </div>
                    <div class="widget-content nopadding">
                        <div class="table_actions">
                            <button id="btnAdd" class="btn  btn-primary">添加</button>
                            <button id="btnEdit" class="btn btn-info">修改</button>
                            <button id="btnDelete" class="btn btn-danger">删除</button>
                        </div>
                        <table id="tablelist" class="layui-table" lay-filter="category_list">
                        </table>
                    </div>
                </div>
            </div>
            <div class="span6">
                <div class="widget-box">
                    <div class="widget-title"><span class="icon"> <i class="icon-th"></i> </span>
                        <h5>测点参数项定义</h5>
                    </div>
                    <div class="widget-content nopadding">
                        <div class="table_actions">
                            <button id="btnAddItem" class="btn btn-primary">添加</button>
                            <button id="btnEditItem" class="btn btn-info">修改</button>
                            <button id="btnDeleteItem" class="btn btn-danger">删除</button>
                            <button id="btnUpItem" class="btn btn-danger">上移</button>
                            <button id="btnDownItem" class="btn btn-danger">下移</button>
                            <button id="btnTopItem" class="btn btn-danger">置顶</button>
                            <button id="btnBottomItem" class="btn btn-danger">置底</button>
                        </div>
                        <table id="itemlist" class="layui-table">
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title"><span class="icon"> <i class="icon-th"></i> </span>
                        <h5>测点参数项定义</h5>
                    </div>
                    <div class="widget-content nopadding">
                        <div class="table_actions">
                            <button id="btnAddOption" class="btn btn-primary">添加</button>
                            <button id="btnEditOption" class="btn btn-info">修改</button>
                            <button id="btnDeleteOption" class="btn btn-danger">删除</button>
                            <button id="btnUpOption" class="btn btn-danger">上移</button>
                            <button id="btnDownOption" class="btn btn-danger">下移</button>
                            <button id="btnTopOption" class="btn btn-danger">置顶</button>
                            <button id="btnBottomOption" class="btn btn-danger">置底</button>
                        </div>
                        <table id="optionlist" class="layui-table">
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div style="position:absolute;left:-99999999px;">
    <div id="eigenValueAll" class="row-fluid" style="margin:10px auto;width:650px;height:320px;">
        <div class="widget-box">
            <div class="widget-title"><span class="icon"> <i class="icon-align-justify"></i> </span>
                <h5>选择特征值</h5>
            </div>
            <div class="widget-content nopadding">
                <table class="layui-hide" id="eigenValueAllTable"></table>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/resources/matrix/js/jquery.min.js}"></script>
<script th:src="@{/resources/matrix/js/jquery.ui.custom.js}"></script>
<script th:src="@{/resources/matrix/js/bootstrap.min.js}"></script>
<script th:src="@{/resources/matrix/js/matrix.js}"></script>
<script th:src="@{/resources/js/website.js}"></script>
<script th:src="@{/resources/layui/layui.all.js}" charset="utf-8"></script>
<script th:src="@{/resources/jquery-easyui/jquery.easyui.min.js}"></script>
<script th:src="@{/resources/js/monitor/eigenvalue_operation.js}"></script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var contextRoot = $("meta[name='context-path']").attr("content");

    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            search();
        }
    });
    /*]]>*/
</script>

<script th:inline="javascript">
    /*<![CDATA[*/
    var data = JSON.parse([[${eigenValues}]]);
    var selectedData = [];
    var query, add, edit, del, queryItem, addItem, editItem, deleteItem, upItem, downItem, topItem, bottomItem,
        categoryId;
    layui.use(['jquery', 'layer', 'table', 'laydate'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            table = layui.table;

        lay('.date').each(function () {
            laydate.render({
                elem: this
            });
        });

        var cols = [
            [
                {field: 'ck', checkbox: true},
                {field: 'name', title: '名称', width: '25%', align: 'center', sortable: true, fixed: true, fit: true},
                {field: 'createTime', title: '创建时间', width: '25%', align: 'center', sortable: true, fixed: true},
                {field: 'description', title: '描述', width: '45%', align: 'center', sortable: true, fixed: true}
            ]
        ];

        query = new ListQuery22(table, {
            cols: cols,
            element: "#tablelist",
            url: contextRoot + "jwQuestion/doListQuestion",
            page: 1,
            single: true,
            filter: "category_list",
            tableid: "point_category_list_table",
            extraData: function () {
                return $("#queryform").serializeObject();
            },
            onRowChecked: function (row) {
                categoryId = row.data.id;
                queryItem.reload();
                loadExistEigenValues(categoryId);
            },
            onReload: function () {
                categoryId = null;
            }
        })
        ;
        query.reload();

        add = new ListAdd(layer, {
            title: "添加测点类别",
            url: contextRoot + "jwQuestion/getAddQuestion",
            width: "730px",
            height: "360px"
        }, query);

        edit = new ListEdit(layer, {
            title: "修改测点类别",
            url: contextRoot + "pointCategory/getEditPointCategory",
            width: "730px",
            height: "360px"
        }, query);

        del = new ListDelete(layer, query, {
            url: contextRoot + "pointCategory/doDeletePointCategory"
        });

        $("#btnAdd").bind("click", function (event) {
            add.openDialog();
        });

        $("#btnSearch").bind("click", function (event) {
            query.reload();
        });

        $("#btnEdit").bind("click", function (event) {
            edit.openDialog();
        });

        $("#btnDelete").bind("click", function (event) {
            del.submit();
        });

        //item
        var colItems = [
            [
                {field: 'ck', checkbox: true},
                {field: 'name', title: '名称', width: '25%', align: 'center', sortable: true, fixed: true, fit: true},
                {field: 'createTime', title: '创建时间', width: '25%', align: 'center', sortable: true, fixed: true},
                {field: 'description', title: '描述', width: '40%', align: 'center', sortable: true, fixed: true}
            ]
        ];

        queryItem = new ListQuery22(table, {
            cols: colItems,
            element: "#itemlist",
            url: contextRoot + "jwQuestionItem/doListPointCategoryItem",
            page: 1,
            single:true,
            pageable: false,
            tableid: "point_category_item_list_table",
            extraData: function () {
                return {parentId: categoryId};
            }
        });

        addItem = new ListAdd(layer, {
            title: "添加测点类别",
            url: contextRoot + "pointCategoryItem/getAddPointCategoryItem",
            width: "730px",
            height: "360px",
            getUrl: function (url) {
                return url + "/" + categoryId;
            }
        }, queryItem);

        editItem = new ListEdit(layer, {
            title: "修改测点类别",
            url: contextRoot + "pointCategoryItem/getEditPointCategoryItem",
            width: "730px",
            height: "360px",
            getUrl: function (url) {
                return url + "/" + categoryId;
            }
        }, queryItem);

        deleteItem = new ListDelete(layer, queryItem, {
            url: contextRoot + "pointCategoryItem/doDeletePointCategoryItem"
        });

        // upItem = new ListOrder(layer, queryItem, {
        //     getUrl: function () {
        //         return contextRoot + "pointCategoryItem/doUpPointCategoryItemOrder/" + categoryId;
        //     }
        // });

        // downItem = new ListOrder(layer, queryItem, {
        //     getUrl: function () {
        //         return contextRoot + "pointCategoryItem/doDownPointCategoryItemOrder/" + categoryId;
        //     }
        // });

        // topItem = new ListOrder(layer, queryItem, {
        //     getUrl: function () {
        //         return contextRoot + "pointCategoryItem/doTopPointCategoryItemOrder/" + categoryId;
        //     }
        // });

        // bottomItem = new ListOrder(layer, queryItem, {
        //     getUrl: function () {
        //         return contextRoot + "pointCategoryItem/doBottomPointCategoryItemOrder/" + categoryId;
        //     }
        // });

        $("#btnAddItem").bind("click", function (event) {
            if (categoryId) {
                addItem.openDialog();
            }
        });

        $("#btnEditItem").bind("click", function (event) {
            if (categoryId) {
                editItem.openDialog();
            }
        });

        $("#btnDeleteItem").bind("click", function (event) {
            deleteItem.submit();
        });

        $("#btnUpItem").bind("click", function (event) {
            upItem.submit();
        });

        $("#btnDownItem").bind("click", function (event) {
            downItem.submit();
        });

        $("#btnTopItem").bind("click", function (event) {
            topItem.submit();
        });

        $("#btnBottomItem").bind("click", function (event) {
            bottomItem.submit();
        });

        //eigen
        var colEigens = [
            [
                {type: 'checkbox'},
                {field: 'name', title: '名称', sort: true},
                {field: 'code', width: '30%', title: '编码'},
                {field: 'unit', width: '30%', edit: 'text', title: '单位'},
            ]
        ];

        var loadExistEigenValues = function () {
            ajaxPost(contextRoot + "pointEigenItem/doListPointEigenItem", {parentId: categoryId}, function (data) {
                selectedData = data;
                loadTableSelectedData(selectedData);
            }, function (error) {
            });
        };

        table.on('edit(eigenValueTable)', function (obj) {
            var val = obj.value //得到修改后的值
            index = obj.data.LAY_TABLE_INDEX
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            selectedData[index][field] = val;
        });

        $("#btnEditEigenValue").bind("click", function (event) {
            showEigenValueDialog(function () {
                layer.msg("点击保存按钮生效！");
            });
        });

        $("#btnSaveEigenValue").bind("click", function (event) {
            var data = JSON.stringify(selectedData);
            ajaxPost(contextRoot + "pointEigenItem/doSavePointEigenItem", {
                parentId: categoryId,
                eigenValues: data
            }, function (data) {
                layer.msg("保存成功");
            }, function (error) {
                layer.msg("保存失败");
            });
        });

        $("#btnDeleteEigenValue").bind("click", function (event) {
            deleteSelectedEigenValues();
        });

        initTable(table, data, selectedData, colEigens);
    });
    /*]]>*/
</script>
</body>
</html>